package com.cabd.web.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cabd.service.ShowInfo;
import com.cabd.service.impl.ShowInfoImpl;
import com.cabd.staticfinal.PythonFilePath;

@WebServlet("/showSourcePython")
public class ShowSourcePython extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String fileName = request.getParameter("fileName");
		String path = "";
		if(fileName.equals("flight_ceshi"))
			path = PythonFilePath.SourceFlightCeshi;
		else if (fileName.equals("flight"))
			path  =PythonFilePath.SourceFileFlight;
		else if (fileName.equals("sk"))
			path = PythonFilePath.SourceFileSk;
		
		ShowInfo showInfo = new ShowInfoImpl();
		
		ArrayList<String> aList = showInfo.showScource(path);
		
		request.setAttribute("sourceCode", aList);
		request.setAttribute("lines", aList.size());
		request.setAttribute("fileName", fileName+".py");
		request.getRequestDispatcher("/ShowSource.jsp").forward(request, response);
		
			
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}